home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / arkanoid.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  184 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. static int flipscreen[2];
  15. static int gfxbank,palettebank;
  16. extern int arkanoid_paddle_select;
  17. extern int arkanoid_coin_lockout;
  18.  
  19.  
  20.  
  21. /***************************************************************************
  22.  
  23.   Convert the color PROMs into a more useable format.
  24.  
  25.   Arkanoid has a three 512x4 palette PROMs (one per gun).
  26.   I don't know the exact values of the resistors between the RAM and the
  27.   RGB output. I assumed these values (the same as Commando)
  28.  
  29.   bit 3 -- 220 ohm resistor  -- RED/GREEN/BLUE
  30.         -- 470 ohm resistor  -- RED/GREEN/BLUE
  31.         -- 1  kohm resistor  -- RED/GREEN/BLUE
  32.   bit 0 -- 2.2kohm resistor  -- RED/GREEN/BLUE
  33.  
  34. ***************************************************************************/
  35. void arkanoid_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  36. {
  37.     int i;
  38.  
  39.  
  40.     for (i = 0;i < Machine->drv->total_colors;i++)
  41.     {
  42.         int bit0,bit1,bit2,bit3;
  43.  
  44.         /* red component */
  45.         bit0 = (color_prom[0] >> 0) & 0x01;
  46.         bit1 = (color_prom[0] >> 1) & 0x01;
  47.         bit2 = (color_prom[0] >> 2) & 0x01;
  48.         bit3 = (color_prom[0] >> 3) & 0x01;
  49.         *(palette++) =  0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  50.         /* green component */
  51.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  52.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  53.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  54.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  55.         *(palette++) =  0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  56.         /* blue component */
  57.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  58.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  59.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  60.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  61.         *(palette++) =  0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  62.  
  63.         color_prom++;
  64.     }
  65. }
  66.  
  67.  
  68.  
  69. WRITE_HANDLER( arkanoid_d008_w )
  70. {
  71.     /* bits 0 and 1 flip X and Y, I don't know which is which */
  72.     if (flipscreen[0] != (data & 0x01))
  73.     {
  74.         flipscreen[0] = data & 0x01;
  75.         memset(dirtybuffer,1,videoram_size);
  76.     }
  77.     if (flipscreen[1] != (data & 0x02))
  78.     {
  79.         flipscreen[1] = data & 0x02;
  80.         memset(dirtybuffer,1,videoram_size);
  81.     }
  82.  
  83.     /* bit 2 selects the input paddle */
  84.     arkanoid_paddle_select = data & 0x04;
  85.  
  86.     /* bit 3 is coin lockout (but not the service coin) */
  87.     coin_lockout_w(0, !(data & 0x08));
  88.     coin_lockout_w(1, !(data & 0x08));
  89.  
  90.     /* bit 4 is unknown */
  91.  
  92.     /* bits 5 and 6 control gfx bank and palette bank. They are used together */
  93.     /* so I don't know which is which. */
  94.     if (gfxbank != ((data & 0x20) >> 5))
  95.     {
  96.         gfxbank = (data & 0x20) >> 5;
  97.         memset(dirtybuffer,1,videoram_size);
  98.     }
  99.     if (palettebank != ((data & 0x40) >> 6))
  100.     {
  101.         palettebank = (data & 0x40) >> 6;
  102.         memset(dirtybuffer,1,videoram_size);
  103.     }
  104.  
  105.     /* bit 7 is unknown */
  106. }
  107.  
  108.  
  109.  
  110. /***************************************************************************
  111.  
  112.   Draw the game screen in the given osd_bitmap.
  113.   Do NOT call osd_update_display() from this function, it will be called by
  114.   the main emulation engine.
  115.  
  116. ***************************************************************************/
  117. void arkanoid_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  118. {
  119.     int offs;
  120.  
  121.  
  122.     /* for every character in the Video RAM, check if it has been modified */
  123.     /* since last time and update it accordingly. */
  124.     for (offs = videoram_size - 2;offs >= 0;offs -= 2)
  125.     {
  126.         int offs2;
  127.  
  128.         offs2 = offs/2;
  129.         if (dirtybuffer[offs] || dirtybuffer[offs+1])
  130.         {
  131.             int sx,sy,code;
  132.  
  133.  
  134.             dirtybuffer[offs] = 0;
  135.             dirtybuffer[offs + 1] = 0;
  136.  
  137.             sx = offs2 % 32;
  138.             sy = offs2 / 32;
  139.  
  140.             if (flipscreen[0]) sx = 31 - sx;
  141.             if (flipscreen[1]) sy = 31 - sy;
  142.  
  143.             code = videoram[offs + 1] + ((videoram[offs] & 0x07) << 8) + 2048 * gfxbank;
  144.             drawgfx(tmpbitmap,Machine->gfx[0],
  145.                     code,
  146.                     ((videoram[offs] & 0xf8) >> 3) + 32 * palettebank,
  147.                     flipscreen[0],flipscreen[1],
  148.                     8*sx,8*sy,
  149.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  150.         }
  151.     }
  152.  
  153.  
  154.     /* copy the temporary bitmap to the screen */
  155.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  156.  
  157.  
  158.     /* Draw the sprites. */
  159.     for (offs = 0;offs < spriteram_size;offs += 4)
  160.     {
  161.         int sx,sy,code;
  162.  
  163.  
  164.         sx = spriteram[offs];
  165.         sy = 248 - spriteram[offs + 1];
  166.         if (flipscreen[0]) sx = 248 - sx;
  167.         if (flipscreen[1]) sy = 248 - sy;
  168.  
  169.         code = spriteram[offs + 3] + ((spriteram[offs + 2] & 0x03) << 8) + 1024 * gfxbank;
  170.         drawgfx(bitmap,Machine->gfx[0],
  171.                 2 * code,
  172.                 ((spriteram[offs + 2] & 0xf8) >> 3) + 32 * palettebank,
  173.                 flipscreen[0],flipscreen[1],
  174.                 sx,sy + (flipscreen[1] ? 8 : -8),
  175.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  176.         drawgfx(bitmap,Machine->gfx[0],
  177.                 2 * code + 1,
  178.                 ((spriteram[offs + 2] & 0xf8) >> 3) + 32 * palettebank,
  179.                 flipscreen[0],flipscreen[1],
  180.                 sx,sy,
  181.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  182.     }
  183. }
  184.